class ProtectionForm {
var $mRestrictions = array();
var $mReason = '';
-
+
function ProtectionForm( &$article ) {
global $wgRequest, $wgUser;
global $wgRestrictionTypes, $wgRestrictionLevels;
$this->mArticle =& $article;
$this->mTitle =& $article->mTitle;
-
+
if( $this->mTitle ) {
foreach( $wgRestrictionTypes as $action ) {
// Fixme: this form currently requires individual selections,
$this->mRestrictions[$action] = implode( '', $this->mTitle->getRestrictions( $action ) );
}
}
-
+
// The form will be available in read-only to show levels.
$this->disabled = !$wgUser->isAllowed( 'protect' ) || wfReadOnly() || $wgUser->isBlocked();
$this->disabledAttrib = $this->disabled
? array( 'disabled' => 'disabled' )
: array();
-
+
if( $wgRequest->wasPosted() ) {
$this->mReason = $wgRequest->getText( 'mwProtect-reason' );
foreach( $wgRestrictionTypes as $action ) {
}
}
}
-
+
function show() {
global $wgOut;
-
+
$wgOut->setRobotpolicy( 'noindex,nofollow' );
if( is_null( $this->mTitle ) ||
$wgOut->fatalError( wfMsg( 'badarticleerror' ) );
return;
}
-
+
if( $this->save() ) {
$wgOut->redirect( $this->mTitle->getFullUrl() );
return;
}
-
+
$wgOut->setPageTitle( wfMsg( 'confirmprotect' ) );
$wgOut->setSubtitle( wfMsg( 'protectsub', $this->mTitle->getPrefixedText() ) );
-
+
$wgOut->addWikiText(
wfMsg( $this->disabled ? "protect-viewtext" : "protect-text",
$this->mTitle->getPrefixedText() ) );
-
+
$wgOut->addHTML( $this->buildForm() );
-
+
$this->showLogExtract( $wgOut );
}
-
+
function save() {
global $wgRequest, $wgUser;
if( !$wgRequest->wasPosted() ) {
return false;
}
-
+
if( $this->disabled ) {
return false;
}
-
+
$token = $wgRequest->getVal( 'wpEditToken' );
if( !$wgUser->matchEditToken( $token ) ) {
$wgOut->fatalError( wfMsg( 'sessionfailure' ) );
return false;
}
-
+
$ok = $this->mArticle->updateRestrictions( $this->mRestrictions, $this->mReason );
if( !$ok ) {
$wgOut->fatalError( "Unknown error at restriction save time." );
}
return $ok;
}
-
+
function buildForm() {
global $wgUser;
-
+
$out = '';
if( !$this->disabled ) {
$out .= $this->buildScript();
'name' => 'wpEditToken',
'value' => $wgUser->editToken() ) );
}
-
+
$out .= "<table id='mwProtectSet'>";
$out .= "<tbody>";
$out .= "<tr>\n";
$out .= "</td>\n";
}
$out .= "</tr>\n";
-
+
// JavaScript will add another row with a value-chaining checkbox
-
+
$out .= "</tbody>\n";
$out .= "</table>\n";
-
+
if( !$this->disabled ) {
$out .= "<table>\n";
$out .= "<tbody>\n";
$out .= "</form>\n";
$out .= $this->buildCleanupScript();
}
-
+
return $out;
}
-
+
function buildSelector( $action, $selected ) {
global $wgRestrictionLevels;
$id = 'mwProtect-level-' . $action;
'size' => count( $wgRestrictionLevels ),
'onchange' => 'protectLevelsUpdate(this)',
) + $this->disabledAttrib;
-
+
$out = wfOpenElement( 'select', $attribs );
foreach( $wgRestrictionLevels as $key ) {
$out .= $this->buildOption( $key, $selected );
$out .= "</select>\n";
return $out;
}
-
+
function buildOption( $key, $selected ) {
$text = ( $key == '' )
? wfMsg( 'protect-default' )
array( 'value' => $key ) + $selectedAttrib,
$text );
}
-
+
function buildReasonInput() {
$id = 'mwProtect-reason';
return wfElement( 'label', array(
'name' => $id,
'id' => $id ) );
}
-
+
function buildSubmit() {
return wfElement( 'input', array(
'type' => 'submit',
'value' => wfMsg( 'confirm' ) ) );
}
-
+
function buildScript() {
global $wgStylePath;
return '<script type="text/javascript" src="' .
htmlspecialchars( $wgStylePath . "/common/protect.js" ) .
'"></script>';
}
-
+
function buildCleanupScript() {
return '<script type="text/javascript">protectInitialize("mwProtectSet","' .
wfEscapeJsString( wfMsg( 'protect-unchain' ) ) . '")</script>';
}
-
+
/**
* @param OutputPage $out
* @access private